package engine.graphics.anim
{
	import engine.math.*;
	
	public class RxAnimatedParamBase
	{
		protected var m_timeFadeInStart:Number;
		protected var m_timeFadeInEnd:Number;
		protected var m_timeFadeOutStart:Number;
		protected var m_timeFadeOutEnd:Number;
		protected var m_timeRepeat:Number;
		protected var m_timeCurrent:Number;
		protected var m_fadeInDeltaRcp:Number;
		protected var m_fadeOutDeltaRcp:Number;
		protected var m_featuresMask:uint;
		protected var m_running:Boolean;
		public static const TIME_FADE:uint = 1;
		public static const FUNC_SINUSOIDAL:uint = 2;
		public static const FUNC_PERLIN_NOISE:uint = 4;
		public static const FUNC_RANDOM_NOISE:uint = 8;
		public static var s_perlinNoise:RxPerlinNoise = new RxPerlinNoise();
		
		public function RxAnimatedParamBase()
		{
			Init();
		}
		
		public function Init() : void
		{
			this.m_timeFadeInStart = 0;
			this.m_timeFadeInEnd = 0;
			this.m_timeFadeOutStart = 0;
			this.m_timeFadeOutEnd = 0;
			this.m_timeRepeat = 0;
			this.m_timeCurrent = 0;
			this.m_fadeInDeltaRcp = 0;
			this.m_fadeOutDeltaRcp = 0;
			this.m_featuresMask = 0;
			this.m_running = false;
		}
		
		public function SetupFromXML(list:XMLList) : void
		{
			var InStart:* = list.@fadeInStart;
			var InEnd:* = list.@fadeInEnd;
			var OutStart:* = list.@fadeOutStart;
			var OutEnd:* = list.@fadeOutEnd;
			this.SetTimes(InStart, InEnd, OutStart, OutEnd);
			this.m_timeRepeat = list.@repeat;
			var timeFunc:* = list.@timeFunc;
			if (list.@timeFunc != "")
			{
				if (timeFunc.search("sine") != -1)
				{
					this.m_featuresMask = this.m_featuresMask | FUNC_SINUSOIDAL;
				}
				if (timeFunc.search("perlin") != -1)
				{
					this.m_featuresMask = this.m_featuresMask | FUNC_PERLIN_NOISE;
				}
				if (timeFunc.search("random") != -1)
				{
					this.m_featuresMask = this.m_featuresMask | FUNC_RANDOM_NOISE;
				}
			}
		}
		
		public function SetTimes(InStart:Number, InEnd:Number, OutStart:Number, OutEnd:Number) : void
		{
			this.m_timeFadeInStart = InStart;
			this.m_timeFadeInEnd = InEnd;
			this.m_timeFadeOutStart = OutStart;
			this.m_timeFadeOutEnd = OutEnd;
			if (this.m_timeFadeInEnd != this.m_timeFadeInStart)
			{
				this.m_fadeInDeltaRcp = 1 / (this.m_timeFadeInEnd - this.m_timeFadeInStart);
			}
			else
			{
				this.m_fadeInDeltaRcp = 0;
			}
			if (this.m_timeFadeOutEnd != this.m_timeFadeOutStart)
			{
				this.m_fadeOutDeltaRcp = 1 / (this.m_timeFadeOutEnd - this.m_timeFadeOutStart);
			}
			else
			{
				this.m_fadeOutDeltaRcp = 0;
			}
		}
	}
}